package com.skateboard.reelviewtest;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Rect;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.HorizontalScrollView;
/**
 * @作者： xuze
 * @时间： 2020/12/15 2:35 PM
 * @描述： view 裁剪
 */
public class ViewSubViriableActivity extends AppCompatActivity implements View.OnClickListener {
    HorizontalScrollView scroll_view;
    Button btn_test;
    Rect originRect = new Rect();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_sub_viriable);
        scroll_view=findViewById(R.id.scroll_view);
        btn_test=findViewById(R.id.btn_test);
        btn_test.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        test();
    }

    private void test(){
        scroll_view.getGlobalVisibleRect(originRect);
        int centerX = (originRect.right - originRect.left) / 2;
        int centerY = (originRect.bottom - originRect.top) / 2;
        //设置View的显示区域，坐标是自身
        Rect tmp = new Rect(centerX - 150, centerY - 150, centerX + 150, centerY + 150);
        scroll_view.setClipBounds(tmp);
    }
}